home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / xlisp / xldmem.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  15.7 KB  |  441 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:        xldmem.h
  5. * RCS:        $Header: xldmem.h,v 1.8 91/03/14 03:37:02 mayer Exp $
  6. * Description:    dynamic memory definitions
  7. * Author:    David Michael Betz; Niels Mayer
  8. * Created:    
  9. * Modified:     Fri Oct  4 04:17:05 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:    C
  11. * Package:    N/A
  12. * Status:    X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41.  
  42.  
  43. /* small fixnum range */
  44. #define SFIXMIN        (-128)
  45. #define SFIXMAX        255
  46. #define SFIXSIZE    384
  47.  
  48. /* character range */
  49. #define CHARMIN        0
  50. #define CHARMAX        255
  51. #define CHARSIZE    256
  52.  
  53. /* new node access macros */
  54. #define ntype(x)    ((x)->n_type)
  55.  
  56. /* cons access macros */
  57. #define car(x)        ((x)->n_car)
  58. #define cdr(x)        ((x)->n_cdr)
  59. #define rplaca(x,y)    ((x)->n_car = (y))
  60. #define rplacd(x,y)    ((x)->n_cdr = (y))
  61.  
  62. /* symbol access macros */
  63. #define getvalue(x)     ((x)->n_vdata[0])
  64. #define setvalue(x,v)     ((x)->n_vdata[0] = (v))
  65. #define getfunction(x)     ((x)->n_vdata[1])
  66. #define setfunction(x,v) ((x)->n_vdata[1] = (v))
  67. #define getplist(x)     ((x)->n_vdata[2])
  68. #define setplist(x,v)     ((x)->n_vdata[2] = (v))
  69. #define getpname(x)     ((x)->n_vdata[3])
  70. #define setpname(x,v)     ((x)->n_vdata[3] = (v))
  71. #define SYMSIZE        4
  72.  
  73. /* closure access macros */
  74. #define getname(x)    ((x)->n_vdata[0])
  75. #define setname(x,v)    ((x)->n_vdata[0] = (v))
  76. #define gettype(x)    ((x)->n_vdata[1])
  77. #define settype(x,v)    ((x)->n_vdata[1] = (v))
  78. #define getargs(x)    ((x)->n_vdata[2])
  79. #define setargs(x,v)    ((x)->n_vdata[2] = (v))
  80. #define getoargs(x)    ((x)->n_vdata[3])
  81. #define setoargs(x,v)    ((x)->n_vdata[3] = (v))
  82. #define getrest(x)    ((x)->n_vdata[4])
  83. #define setrest(x,v)    ((x)->n_vdata[4] = (v))
  84. #define getkargs(x)    ((x)->n_vdata[5])
  85. #define setkargs(x,v)    ((x)->n_vdata[5] = (v))
  86. #define getaargs(x)    ((x)->n_vdata[6])
  87. #define setaargs(x,v)    ((x)->n_vdata[6] = (v))
  88. #define getbody(x)    ((x)->n_vdata[7])
  89. #define setbody(x,v)    ((x)->n_vdata[7] = (v))
  90. #ifdef WINTERP            /* note: changed getenv()-->getenvt() due to name conflict with stdlib.h:getenv() */
  91. #define getenvt(x)    ((x)->n_vdata[8])
  92. #else
  93. #define getenv(x)    ((x)->n_vdata[8])
  94. #endif                /* WINTERP */
  95. #define setenv(x,v)    ((x)->n_vdata[8] = (v))
  96. #define getfenv(x)    ((x)->n_vdata[9])
  97. #define setfenv(x,v)    ((x)->n_vdata[9] = (v))
  98. #define getlambda(x)    ((x)->n_vdata[10])
  99. #define setlambda(x,v)    ((x)->n_vdata[10] = (v))
  100. #define CLOSIZE        11
  101.  
  102. /* vector access macros */
  103. #define getsize(x)    ((x)->n_vsize)
  104. #define getelement(x,i)    ((x)->n_vdata[i])
  105. #define setelement(x,i,v) ((x)->n_vdata[i] = (v))
  106.  
  107. /* object access macros */
  108. #define getclass(x)    ((x)->n_vdata[0])
  109. #define getivar(x,i)    ((x)->n_vdata[i+1])
  110. #define setivar(x,i,v)    ((x)->n_vdata[i+1] = (v))
  111.  
  112. /* subr/fsubr access macros */
  113. #define getsubr(x)    ((x)->n_subr)
  114. #define getoffset(x)    ((x)->n_offset)
  115.  
  116. /* fixnum/flonum/char access macros */
  117. #define getfixnum(x)    ((x)->n_fixnum)
  118. #define getflonum(x)    ((x)->n_flonum)
  119. #define getchcode(x)    ((x)->n_chcode)
  120.  
  121. /* string access macros */
  122. #define getstring(x)    ((x)->n_string)
  123. #define getslength(x)    ((x)->n_strlen)
  124.  
  125. /* file stream access macros */
  126. #define getfile(x)    ((x)->n_fp)
  127. #define setfile(x,v)    ((x)->n_fp = (v))
  128. #define getsavech(x)    ((x)->n_savech)
  129. #define setsavech(x,v)    ((x)->n_savech = (v))
  130.  
  131. /* unnamed stream access macros */
  132. #define gethead(x)    ((x)->n_car)
  133. #define sethead(x,v)    ((x)->n_car = (v))
  134. #define gettail(x)    ((x)->n_cdr)
  135. #define settail(x,v)    ((x)->n_cdr = (v))
  136.  
  137. #ifdef WINTERP
  138.  
  139. #include <Xm/Xm.h>
  140.  
  141. /* XLTYPE_XT_RESOURCE access macros */
  142. #define get_xtresource(x)       ((x)->n_xtresource)
  143.  
  144. /* XLTYPE_Pixel access macros */
  145. #define get_pixel(x)           ((x)->n_pixel)
  146.  
  147. /* XLTYPE_Pixmap access macros */
  148. #define get_pixmap(x)           ((x)->n_pixmap)
  149.  
  150. /* XLTYPE_XImage access macros */
  151. #define get_ximage(x)           ((x)->n_ximage)
  152.  
  153. /* XLTYPE_XmString access macros */
  154. #define get_xmstring(x)           ((x)->n_xmstring)
  155.  
  156. /* XLTYPE_XEvent access macros */
  157. #define get_xevent(x)       ((x)->n_xevent)
  158.  
  159. /* XLTYPE_Window access macros */
  160. #define get_window(x)           ((x)->n_window)
  161.  
  162. /* XLTYPE_PIXMAP_REFOBJ access macros */
  163. #define get_pixref_pixmap(x)       ((x)->n_vdata[0])
  164. #define set_pixref_pixmap(x,v)       ((x)->n_vdata[0] = (v))
  165. #define get_pixref_widget(x)       ((x)->n_vdata[1])
  166. #define set_pixref_widget(x,v)       ((x)->n_vdata[1] = (v))
  167. #define get_pixref_resname(x)       ((x)->n_vdata[2])
  168. #define set_pixref_resname(x,v)       ((x)->n_vdata[2] = (v))
  169. #define PIXMAP_REFOBJ_SIZE 3
  170.  
  171. /* XLTYPE_CALLBACKOBJ access macros */
  172. #define get_callback_widget(x)       ((x)->n_vdata[0])
  173. #define set_callback_widget(x,v)   ((x)->n_vdata[0] = (v))
  174. #define get_callback_name(x)       ((char *) getfixnum((x)->n_vdata[1]))
  175. #define set_callback_name(x,v)       ((x)->n_vdata[1] = cvfixnum((FIXTYPE) (v))) /* note that (v) is of type char* */
  176. #define get_callback_proc(x)       ((XtCallbackProc) getfixnum((x)->n_vdata[2]))
  177. #define set_callback_proc(x,v)       ((x)->n_vdata[2] = cvfixnum((FIXTYPE) (v))) /* note that (v) is of type XtCallbackProc */
  178. #define get_callback_closure(x)       ((x)->n_vdata[3])
  179. #define set_callback_closure(x,v)  ((x)->n_vdata[3] = (v))
  180. #define CALLBACKOBJ_SIZE 4
  181.  
  182. /* XLTYPE_TIMEOUTOBJ access macros */
  183. #define get_timeout_closure(x)       ((x)->n_vdata[0])
  184. #define set_timeout_closure(x,v)   ((x)->n_vdata[0] = (v))
  185. #define get_timeout_id(x)       ((XtIntervalId) getfixnum((x)->n_vdata[1]))
  186. #define set_timeout_id(x,v)       ((x)->n_vdata[1] = cvfixnum((FIXTYPE) (v))) /* note that (v) is of type XtIntervalId */
  187. #define TIMEOUTOBJ_SIZE 2
  188.  
  189. /* XLTYPE_EVHANDLEROBJ access macros */
  190. #define get_evhandler_widget(x)       ((x)->n_vdata[0])
  191. #define set_evhandler_widget(x,v)  ((x)->n_vdata[0] = (v))
  192. #define get_evhandler_mask(x)       ((long) getfixnum((x)->n_vdata[1]))
  193. #define set_evhandler_mask(x,v)       ((x)->n_vdata[1] = cvfixnum((FIXTYPE) (v))) /* note that (v) is of type long */
  194. #define get_evhandler_options(x)   ((long) getfixnum((x)->n_vdata[2]))
  195. #define set_evhandler_options(x,v) ((x)->n_vdata[2] = cvfixnum((FIXTYPE) (v))) /* note that (v) is of type long */
  196. #define get_evhandler_closure(x)   ((x)->n_vdata[3])
  197. #define set_evhandler_closure(x,v) ((x)->n_vdata[3] = (v))
  198. #define EVHANDLEROBJ_SIZE 4
  199.  
  200. /* XLTYPE_WIDGETOBJ access macros -- note that all OBJECT operations work
  201.    on this type too. The main difference between this type and OBJECT
  202.    (both of which are implemented as vectors) is that a WIDGETOBJ holds
  203.    a single instance variable which is an immediate pointer to a WidgetID
  204.    (as opposed to having the slot holding a pointer to an FIXNUM representing
  205.    the WidgetID.) This slot may not be marked since it is
  206.    not a LVAL node. Thus, special code exists in xldmem.c to prevent
  207.    such a problem. The reason for going through all this is that we
  208.    need to do a special operation on the widgetID when a WIDGETOBJ gets
  209.    garbage collected (see sweep()). If the widgetID were another node,
  210.    then the object would be considered "free" and may not hold a valid
  211.    widgetID. Yes, this is a hack. Also, having a separate type for WIDGETOBJs
  212.    makes some operations on WIDGETOBJs more efficient... see w_classes.c */
  213. /* #define getclass(x)      ((x)->n_vdata[0]) --> this macro valid for both this and OBJECT */
  214. #define get_widgetobj_widgetID(x)   (Widget) ((x)->n_vdata[1])
  215. #define set_widgetobj_widgetID(x,v) ((x)->n_vdata[1] = (LVAL) (v))
  216. #define WIDGETOBJ_SIZE 1    /* this val represents the number of instance variables
  217.                    in the object. newobject() will actually create a vector
  218.                    of size WIDGETOBJ_SIZE+1 so as to hold the ivar and the
  219.                    class pointer. */
  220.  
  221. /* XLTYPE_XtAccelerators access macros */
  222. #define get_xtaccelerators(x)          ((x)->n_xtaccelerators)
  223.  
  224. /* XLTYPE_XtTranslations access macros */
  225. #define get_xttranslations(x)          ((x)->n_xttranslations)
  226.  
  227. #endif                /* WINTERP */
  228.  
  229. /* node types */
  230. #define FREE    0
  231. #define SUBR    1
  232. #define FSUBR    2
  233. #define CONS    3
  234. #define SYMBOL    4
  235. #define FIXNUM    5
  236. #define FLONUM    6
  237. #define STRING    7
  238. #define OBJECT    8
  239. #define STREAM    9
  240. #define VECTOR    10
  241. #define CLOSURE    11
  242. #define CHAR    12
  243. #define USTREAM    13
  244. #define STRUCT    14
  245.  
  246. #if (defined(UNIX) || defined(WINTERP))
  247. #define XLTYPE_PIPE 15 /* same node representation as STREAM, different ntype used to distinguish between file and pipe because files get fclose()'d on gc, and pipes get pclose()'d */
  248. #endif /* (defined(UNIX) || defined(WINTERP)) */
  249.  
  250. #ifdef WINTERP
  251.  
  252. #define XLTYPE_XtAccelerators        16
  253. #define XLTYPE_XtTranslations        17
  254. #define XLTYPE_XEvent            18
  255. #define XLTYPE_Window            19
  256. #define XLTYPE_Pixel            20
  257. #define XLTYPE_Pixmap            21
  258. #define XLTYPE_XImage            22
  259. #define XLTYPE_XmString            23
  260. #define XLTYPE_XmFontList        24
  261. #define XLTYPE_XT_RESOURCE        25
  262. #define XLTYPE_CALLBACKOBJ        26
  263. #define XLTYPE_TIMEOUTOBJ        27
  264. #define XLTYPE_PIXMAP_REFOBJ        28
  265. #define XLTYPE_WIDGETOBJ        29
  266. #define XLTYPE_EVHANDLEROBJ        30
  267.  
  268. /* XLTYPE_XT_RESOURCE node */
  269. #define n_xtresource           n_info.n_xresource.xr_resource
  270.  
  271. /* XLTYPE_Pixel node */
  272. #define n_pixel               n_info.n_xpixel.xp_pixel
  273.  
  274. /* XLTYPE_Pixmap node */
  275. #define n_pixmap           n_info.n_xpixmap.xp_pixmap
  276.  
  277. /* XLTYPE_XImage node */
  278. #define n_ximage           n_info.n_xximage.xx_ximage
  279.  
  280. /* XLTYPE_XmString node */
  281. #define n_xmstring           n_info.n_xxmstring.xx_xmstring
  282.  
  283. /* XLTYPE_XEvent node */
  284. #define n_xevent           n_info.n_xxevent.xx_xevent
  285.  
  286. /* XLTYPE_Window node */
  287. #define n_window           n_info.n_xwindow.xw_window
  288.  
  289. /* XLTYPE_XtAccelerators node */
  290. #define n_xtaccelerators       n_info.n_xxtaccelerators.xx_xtaccelerators
  291.  
  292. /* XLTYPE_XtTranslations node */
  293. #define n_xttranslations       n_info.n_xxttranslations.xx_xttranslations
  294.  
  295. #endif                /* WINTERP */
  296.  
  297. /* subr/fsubr node */
  298. #define n_subr        n_info.n_xsubr.xs_subr
  299. #define n_offset    n_info.n_xsubr.xs_offset
  300.  
  301. /* cons node */
  302. #define n_car        n_info.n_xcons.xc_car
  303. #define n_cdr        n_info.n_xcons.xc_cdr
  304.  
  305. /* fixnum node */
  306. #define n_fixnum    n_info.n_xfixnum.xf_fixnum
  307.  
  308. /* flonum node */
  309. #define n_flonum    n_info.n_xflonum.xf_flonum
  310. /* character node */
  311. #define n_chcode    n_info.n_xchar.xc_chcode
  312.  
  313. /* string node */
  314. #define n_string    n_info.n_xstring.xs_string
  315. #define n_strlen    n_info.n_xstring.xs_length
  316.  
  317. /* stream node */
  318. #define n_fp        n_info.n_xstream.xs_fp
  319. #define n_savech    n_info.n_xstream.xs_savech
  320.  
  321. /* vector/object node */
  322. #define n_vsize        n_info.n_xvector.xv_size
  323. #define n_vdata        n_info.n_xvector.xv_data
  324.  
  325. /* node structure */
  326. typedef struct node {
  327.   char n_type;            /* type of node */
  328.   char n_flags;            /* flag bits */
  329.   union ninfo {            /* value */
  330.  
  331. #ifdef WINTERP
  332.  
  333.     struct xresource {        /* XLTYPE_XTRESOURCE node */
  334.       struct _Resource_Instance *xr_resource;
  335.     } n_xresource;
  336.     struct xpixel {        /* XLTYPE_Pixel node */
  337.       Pixel xp_pixel;
  338.     } n_xpixel;
  339.     struct xpixmap {        /* XLTYPE_Pixmap node */
  340.       Pixmap xp_pixmap;
  341.     } n_xpixmap;
  342.     struct xximage {        /* XLTYPE_XImage node */
  343.       XImage *xx_ximage;
  344.     } n_xximage;
  345.     struct xxmstring {        /* XLTYPE_XmString node */
  346.       XmString xx_xmstring;
  347.     } n_xxmstring;
  348.     struct xxevent {        /* XLTYPE_XEvent node */
  349.       XEvent *xx_xevent;
  350.     } n_xxevent;
  351.     struct xwindow {        /* XLTYPE_Window node */
  352.       Window xw_window;
  353.     } n_xwindow;
  354.     struct xxtaccelerators {
  355.       XtAccelerators xx_xtaccelerators;    /* XLTYPE_XtAccelerators node */
  356.     } n_xxtaccelerators;
  357.     struct xxttranslations {
  358.       XtTranslations xx_xttranslations;    /* XLTYPE_XtTranslations node */
  359.     } n_xxttranslations;
  360.  
  361. #endif                /* WINTERP */
  362.  
  363.     struct xsubr {        /* subr/fsubr node */
  364.       struct node *(*xs_subr)(); /* function pointer */
  365.       int xs_offset;        /* offset into funtab */
  366.     } n_xsubr;
  367.     struct xcons {        /* cons node */
  368.       struct node *xc_car;    /* the car pointer */
  369.       struct node *xc_cdr;    /* the cdr pointer */
  370.     } n_xcons;
  371.     struct xfixnum {        /* fixnum node */
  372.       FIXTYPE xf_fixnum;    /* fixnum value */
  373.     } n_xfixnum;
  374.     struct xflonum {        /* flonum node */
  375.       FLOTYPE xf_flonum;    /* flonum value */
  376.     } n_xflonum;
  377.     struct xchar {        /* character node */
  378.       int xc_chcode;        /* character code */
  379.     } n_xchar;
  380.     struct xstring {        /* string node */
  381.       int xs_length;        /* string length */
  382.       unsigned char *xs_string;    /* string pointer */
  383.     } n_xstring;
  384.     struct xstream {        /* stream node */
  385.       FILE *xs_fp;        /* the file pointer */
  386.       int xs_savech;        /* lookahead character */
  387.     } n_xstream;
  388.     struct xvector {        /* vector/object/symbol/structure node */
  389.       int xv_size;        /* vector size */
  390.       struct node **xv_data;    /* vector data */
  391.     } n_xvector;
  392.   } n_info;
  393. } *LVAL;
  394.  
  395. /* memory segment structure definition */
  396. typedef struct segment {
  397.     int sg_size;
  398.     struct segment *sg_next;
  399.     struct node sg_nodes[1];
  400. } SEGMENT;
  401.  
  402. /* memory allocation functions */
  403. extern LVAL cons();        /* (cons x y) */
  404. extern LVAL cvsymbol();        /* convert a string to a symbol */
  405. extern LVAL cvstring();        /* convert a string */
  406. extern LVAL cvfile();        /* convert a FILE * to a file */
  407. extern LVAL cvsubr();        /* convert a function to a subr/fsubr */
  408. extern LVAL cvfixnum();        /* convert a fixnum */
  409. extern LVAL cvflonum();        /* convert a flonum */
  410. extern LVAL cvchar();        /* convert a character */
  411.  
  412. #if (defined(UNIX) || defined(WINTERP))
  413. extern LVAL cv_pipe();        /* create a XLTYPE_PIPE */
  414. #endif /* (defined(UNIX) || defined(WINTERP)) */
  415.  
  416. #ifdef WINTERP
  417. extern LVAL cv_xtresource();    /* convert a pointer to struct _Resource_Instance */
  418. extern LVAL cv_pixel();        /* convert a X11 Pixel to XLTYPE_Pixel */
  419. extern LVAL cv_pixmap();    /* create a XLTYPE_Pixmap */
  420. extern LVAL cv_ximage();    /* create a XLTYPE_XImage */
  421. extern LVAL cv_xmstring();    /* create a XLTYPE_XmString */
  422. extern LVAL cv_xevent();    /* create a XLTYPE_XEvent */
  423. extern LVAL cv_window();    /* create a XLTYPE_Window */
  424. extern LVAL cv_xtaccelerators(); /* create a XLTYPE_XtAccelerators */
  425. extern LVAL cv_xttranslations(); /* create a XLTYPE_XtTranslations */
  426. /* WARNING: use cvstring() to make a copy of the string; the string passed to cv_string will get freed by GC later */
  427. extern LVAL cv_string();    /* create a STRING, see WARNING above... */
  428. extern LVAL new_pixrefobj();    /* create a XLTYPE_PIXMAP_REFOBJ */
  429. extern LVAL new_timeoutobj();    /* create a XLTYPE_TIMEOUTOBJ */
  430. extern LVAL new_callbackobj();    /* create a XLTYPE_CALLBACKOBJ */
  431. extern LVAL new_evhandlerobj();    /* create a XLTYPE_EVHANDLEROBJ */
  432. #endif                /* WINTERP */
  433.  
  434. extern LVAL newstring();    /* create a new string */
  435. extern LVAL newvector();    /* create a new vector */
  436. extern LVAL newobject();    /* create a new object */
  437. extern LVAL newclosure();    /* create a new closure */
  438. extern LVAL newustream();    /* create a new unnamed stream */
  439. extern LVAL newstruct();    /* create a new structure */
  440.